package utils {

	/**
	 * ...
	 * @author jianping.shenjp
	 */
	public class Point3D {
		//焦距
		private var _fl:Number = 250;
		//消失点
		private var _vpX:Number = 0;
		private var _vpY:Number = 0;
		//中心点
		private var _cX:Number = 0;
		private var _cY:Number = 0;
		private var _cZ:Number = 0;
		//坐标位置
		private var _x:Number = 0;
		private var _y:Number = 0;
		private var _z:Number = 0;

		public function Point3D(x:Number = 0, y:Number = 0, z:Number = 0){
			this._x = x;
			this._y = y;
			this._z = z;
		}

		/**
		 * 设置消失点
		 */
		public function setVanishingPoint(vpX:Number, vpY:Number):void {
			this._vpX = vpX;
			this._vpY = vpY;
		}

		/**
		 * 设置中心点
		 */
		public function setCenter(cX:Number, cY:Number, cZ:Number = 0):void {
			this._cX = cX;
			this._cY = cY;
			this._cZ = cZ;
		}

		/**
		 * 获得透视的点在屏幕上的X坐标
		 */
		public function get screenX():Number {
			var scale:Number = _fl / (_fl + _z + _cZ);
			return _vpX + _cX + _x * scale;
		}

		/**
		 * 获得透视的点在屏幕上的Y坐标
		 */
		public function get screenY():Number {
			var scale:Number = _fl / (_fl + _z + _cZ);
			return _vpY + _cY + _y * scale;
		}
        
		public function rotateX(angleX:Number):void {
			var cosX:Number = Math.cos(angleX);
			var sinX:Number = Math.sin(angleX);
			var y1:Number = _y * cosX - _z * sinX;
			var z1:Number = _z * cosX + _y * sinX;
			_y = y1;
			_z = z1;
		}

		public function rotateY(angleY:Number):void {
			var cosY:Number = Math.cos(angleY);
			var sinY:Number = Math.sin(angleY);
			var x1:Number = _x * cosY - _z * sinY;
			var z1:Number = _z * cosY + _x * sinY;
			_x = x1;
			_z = z1;
		}

		public function rotateZ(angleZ:Number):void {
			var cosZ:Number = Math.cos(angleZ);
			var sinZ:Number = Math.sin(angleZ);
			var x1:Number = _x * cosZ - _y * sinZ;
			var y1:Number = _y * cosZ + _x * sinZ;
			_x = x1;
			_y = y1;
		}
        
        /***********************GET & SET*************************/
        public function get x():Number { return _x; }
        
        public function set x(value:Number):void 
        {
            _x = value;
        }
        
        public function get y():Number { return _y; }
        
        public function set y(value:Number):void 
        {
            _y = value;
        }
        
        public function get z():Number { return _z; }
        
        public function set z(value:Number):void 
        {
            _z = value;
        }
	}

}